// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'

Vue.config.productionTip = false

//创建axios对象
let http = axios.create();
//1、设置请求拦截器，将token放在请求头上
http.interceptors.request.use(
  config =>{
    //从sessStroage得到toke
    let token = window.sessionStorage.getItem("token");
    //判断token
    if(token){
      config.headers.authorization = token;
    }
    //放行请求
    return config;
  }
)

//2、设置响应拦截器
http.interceptors.response.use(
  response =>{
    //判断响应头中是否存在token
    let token =response.headers.authorization;
    //存在则放到sessiomStroage
   if(token){
    window.sessionStorage.setItem("token",token);
   }

    return response;
  }
)


Vue.prototype.axios = http
//设置url
Vue.prototype.baseUrl = 'http://localhost:8080/'
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

